;; -*- lexical-binding: t; -*-
;;; emacs
(defalias 'first 'car)
(defalias 'second 'cadr)
(defalias 'rest 'cdr)
(defalias 'list-buffers 'ibuffer)
(add-to-list 'default-frame-alist '(font . "Fixed-8"))
(setenv "PATH" (concat (getenv "PATH") ":/home/goth/.local/bin"))
(setq exec-path (append exec-path '("/home/goth/.local/bin"))
      backup-directory-alist '(("" . "~/.emacs.d/backup"))
      custom-file "~/.emacs.d/custom.el"
      scroll-conservatively 100
      ring-bell-function 'ignore
      frame-resize-pixelwise t
      isearch-lazy-count t
      browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "qutebrowser"
      Man-notify-method 'pushy
      vc-follow-symlinks t
      company-require-match nil)
(load custom-file)
(ido-mode 1)

;;; emms
(require 'emms-setup)
(require 'emms-player-mpd)
(emms-all)
(setq emms-player-list '(emms-player-mpd)
      emms-info-functions '(emms-info-mpd)
      emms-player-mpd-server-name "localhost"
      emms-player-mpd-server-port "6600")
(emms-player-mpd-connect)
(emms-mode-line -1)
(emms-playing-time-disable-display)

;;; eshell
(require 'eshell)
(require 'em-smart)
(require 'esh-autosuggest)
(add-hook 'eshell-mode-hook 'esh-autosuggest-mode)
(add-hook 'eshell-mode-hook 'eshell-smart-initialize)
(eshell-syntax-highlighting-global-mode)
(setq eshell-where-to-jump 'begin
      eshell-review-quick-commands nil
      eshell-smart-space-goes-to-end t
      eshell-banner-message ""
      eshell-hist-ignoredups t
      eshell-history-size 1024
      eshell-cp-interactive-query t
      eshell-mv-interactive-query t)
(require 'esh-module)
(add-to-list 'eshell-modules-list 'eshell-tramp)

;;; exwm
;; (require 'exwm)
;; (require 'exwm-config)
;; (setq exwm-input-global-keys
;;       '(([?\s-x ?r] . exwm-reset)
;; 	([?\s-x ?!] . (lambda (command)
;; 			(interactive (list (read-shell-command "$ ")))
;; 			(start-process-shell-command command nil command)))))
;; (setq exwm-input-simulation-keys
;;           '(([?\C-b] . [left])
;;             ([?\C-f] . [right])
;;             ([?\C-p] . [up])
;;             ([?\C-n] . [down])
;;             ([?\C-a] . [home])
;;             ([?\C-e] . [end])
;;             ([?\M-v] . [prior])
;;             ([?\C-v] . [next])
;;             ([?\C-d] . [delete])
;;             ([?\C-k] . [S-end delete])))
;; (exwm-enable)
;; (exwm-config-ido)

;;; dired
(require 'ls-lisp)
(dired-launch-enable)
(put 'dired-find-alternate-file 'disabled nil)
(add-hook 'dired-mode-hook (lambda () (setq truncate-lines t)))
(add-hook 'dired-mode-hook 'hl-line-mode)
(setq dired-listing-switches "-alh"
      ls-lisp-dirs-first t
      ls-lisp-use-insert-directory-program nil
      dired-launch-extensions-map '(("mp4" 	("mpv"))
				    ("webm" 	("mpv"))
				    ("mkv" 	("mpv"))
				    ("mov" 	("mpv"))
				    ("flv" 	("mpv"))
				    ("wmv"	("mpv"))
				    ("mp3"	("mpv"))
				    ("aac"	("mpv"))
				    ("m4a" 	("mpv"))
				    ("wav"	("mpv"))
				    ("flac"	("mpv"))
				    ("jpg" 	("sxiv.sh"))
				    ("jpeg" 	("sxiv.sh"))
				    ("png" 	("sxiv.sh"))
				    ("gif" 	("sxiv.sh"))))
;; (require 'dired-rainbow)
;; (dired-rainbow-define video "#191970" ("mp4" "webm" "mkv" "mov" "flv" "wmv"))
;; (dired-rainbow-define audio "#4169E1" ("mp3" "aac" "m4a" "wav" "flac"))
;; (dired-rainbow-define image "#4682B4" ("jpg" "jpeg" "png" "gif"))

;;; keybindings
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "C-c h") 'help-command)
(global-set-key (kbd "C-z") 'eshell)
(global-set-key (kbd "<escape>") 'keyboard-quit)
(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window -1)))
(global-set-key (kbd "s-d r") (lambda () (interactive) (dired "/")))
(global-set-key (kbd "s-d h") (lambda () (interactive) (dired "~/")))
(global-set-key (kbd "s-d m") (lambda () (interactive) (dired "~/mnt/")))
(global-set-key (kbd "s-d p") (lambda () (interactive) (dired "~/prog/")))
(global-set-key (kbd "s-d c") (lambda () (interactive) (dired "~/.config/")))
(global-set-key (kbd "s-d i") (lambda () (interactive) (dired "~/Pictures/")))
(global-set-key (kbd "s-d n") (lambda () (interactive) (dired "~/Notes/")))
(global-set-key (kbd "s-m b") 'emms-smart-browse)
(global-set-key (kbd "s-m SPC") 'emms-pause)
(global-set-key (kbd "s-m p") 'emms-previous)
(global-set-key (kbd "s-m n") 'emms-next)
(global-set-key (kbd "s-m r") 'emms-toggle-repeat-track)
(global-set-key (kbd "s-m R") 'emms-toggle-repeat-playlist)
(global-set-key (kbd "s-m c") 'emms-player-mpd-update-all-reset-cache)
(global-set-key (kbd "<f1>") 'guix)
(global-set-key (kbd "<f2>") 'run-guile)
(global-set-key (kbd "<f3>") 'org-agenda-list)
(global-set-key (kbd "<f9>") 'emms-volume-lower)
(global-set-key (kbd "<f10>") 'emms-volume-raise)
(add-hook 'eshell-mode-hook
	  (lambda () 
	    (define-key eshell-mode-map (kbd "C-l")
	      (lambda ()
		(interactive)
		(eshell-smart-goto-end)
		(insert "clear 1")
		(eshell-send-input)))))
(add-hook 'eshell-mode-hook
	  (lambda ()
	    (define-key eshell-mode-map (kbd "M-l")
	      (lambda ()
		(interactive)
		(eshell-bol)
		(kill-line)
		(setq kill-ring (cdr kill-ring))))))
(add-hook 'dired-mode-hook
	  (lambda ()
	    (define-key dired-mode-map (kbd "e")
	      (lambda ()
		(interactive)
		(eshell t)))))

;;; lisp stuff
(show-paren-mode 1)
(setq show-parens-delay 0
      geiser-repl-use-other-window nil)
(add-hook 'paredit-mode-hook 'rainbow-delimiters-mode)
(add-hook 'lisp-mode-hook 'paredit-mode)
(add-hook 'scheme-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'geiser-repl-mode-hook 'paredit-mode)
(add-hook 'sly-mode-hook 'paredit-mode)

;;; mode configuration
(add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
(add-to-list 'auto-mode-alist '("\\.out\\'" . hexl-mode))
(add-to-list 'auto-mode-alist '("\\.mp4\\'" . hexl-mode))
(add-to-list 'auto-mode-alist '("\\.jpg\\'" . hexl-mode))
(add-to-list 'auto-mode-alist '("\\.jpeg\\'" . hexl-mode))
(add-to-list 'auto-mode-alist '("\\.png\\'" . hexl-mode))
(add-to-list 'auto-mode-alist '("\\.mp3\\'" . hexl-mode))
(add-hook 'c-mode-hook 'linum-mode)
(add-hook 'c-mode-hook 'c-toggle-auto-newline)
(add-hook 'package-menu-mode-hook 'hl-line-mode)
(add-hook 'guix-output-list-mode-hook 'hl-line-mode)
(setq python-shell-interpreter "python3")

;;; org-mode and documents
(setq org-hide-emphasis-markers t
      org-agenda-window-setup 'current-window
      org-agenda-files '("~/Notes/Agenda")
      org-roam-directory "~/Notes/org-roam/"
      org-roam-v2-ack t)
(add-hook 'org-mode-hook 'org-indent-mode)
(add-hook 'org-mode-hook 'visual-line-mode)
(pdf-tools-install)
(add-hook 'auto-mode-alist '("\\.epub\\'" . nov-mode))
(setq nov-text-width 80)

;;; packages
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

;;; visual
(scroll-bar-mode -1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(column-number-mode)
(setq inhibit-startup-message t)

;; Local Variables:
;; eval: (rainbow-mode)
;; End:
